<template>
  <div class="app-container">
    <el-form :model="queryParams"
             ref="queryForm"
             size="small"
             inline=true
             v-show="showSearch"
             label-width="68px">
      <el-form-item label="工单编号"
                    prop="repairNo">
        <el-input v-model="queryParams.repairNo"
                  placeholder="编号"
                  clearable
                  @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="工单状态"
                    prop="repairStatus">
        <el-select v-model="queryParams.repairStatus"
                   placeholder="工单状态"
                   clearable>
          <el-option v-for="item in options"
                     :key="item.value"
                     :label="item.label"
                     :value="item.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="选择时间"
                    prop="create_time">
        <el-time-picker v-model="value1"
                        :picker-options="{selectableRange: '00:00:00 - 23:59:59'}"
                        placeholder="选择时间">
        </el-time-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary"
                   icon="el-icon-search"
                   size="mini"
                   @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh"
                   size="mini"
                   @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10"
            class="mb8">

      <el-col :span="10">
        <el-button type="warning"
                   plain
                   icon="el-icon-download"
                   size="mini"
                   @click="handleExport"
                   v-hasPermi="['monitor:job:export']">导出</el-button>
      </el-col>

      <right-toolbar :showSearch.sync="showSearch"
                     @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading"
              :data="myOrderList"
              @selection-change="handleSelectionChange">
      <el-table-column type="selection"
                       width="55"
                       align="center" />
      <el-table-column label="工单编号"
                       width="120"
                       align="center"
                       prop="repairNo" />
      <el-table-column label="问题内容"
                       align="center"
                       prop="repairDescription"
                       :show-overflow-tooltip="true" />
      <el-table-column label="工单发起人"
                       align="center"
                       prop="repairByAndDept">
      </el-table-column>
      <el-table-column label="问题类型"
                       align="center"
                       prop="repairTypeV1"
                       :show-overflow-tooltip="true" />

      <el-table-column label="提交时间"
                       align="center"
                       prop="createTime">
      </el-table-column>
      <el-table-column label="受理时间"
                       align="center"
                       prop="updateTime">
      </el-table-column>

      <el-table-column label="工单状态"
                       align="center"
                       prop="repairStatus"
                       >
        <!-- <template slot-scope="scope"> -->
        <!-- <dict-tag :options="dict.type.sys_normal_disable"
                    :value="scope.row.qualitiedTime"
                    :formatter="formatempempPolitics"
                     /> -->
        <template slot-scope="scope">
          <dict-tag :options="dict.type.rp_repair_order_status"
                    :value="scope.row.repairStatus" />
        </template>
      </el-table-column>


      <el-table-column label="操作"
                       align="center"
                       class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <router-link :to="{path:'/work/qualitied-qualitiedDeal/?id='+scope.row.repairOrderId}">
            <el-button size="mini"
                       type="text"
                       icon="el-icon-edit"
                       @click="handleUpdate(scope.row)"
                       v-hasPermi="['tool:gen:edit']">回复</el-button>
          </router-link>

          <el-button size="mini"
                     type="text"
                     icon="el-icon-edit"
                     @click="handleCheck(scope.row)"
                     v-hasPermi="['monitor:job:remove']">查看</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-drawer title="我是标题"
               :visible.sync="drawer"
               :with-header="false">
      <el-row>
        <el-col :span="24"
                class="card-box">
          <el-card>
            <div slot="header"><span>工单质检</span></div>
            <div class="el-table el-table--enable-row-hover el-table--medium">
              <table cellspacing="0"
                     style="width: 100%;"
                     :model="form">
                <thead>
                  <tr>
                    <th class="el-table__cell is-leaf">
                      <div class="cell">质检项</div>
                    </th>
                    <th class="el-table__cell is-leaf">
                      <div class="cell">得分</div>
                    </th>
                  </tr>
                </thead>
                <tbody>
                  <tr style="height:80px;">
                    <td class="el-table__cell is-leaf">
                      <div class="cell">语言</div>
                    </td>
                    <td class="el-table__cell is-leaf">
                      <div class="cell">
                        <el-input style="width:80px;"
                                  v-model="form.languageCore"></el-input>
                      </div>
                    </td>
                  </tr>
                  <tr style="height:80px;">
                    <td class="el-table__cell is-leaf">
                      <div class="cell">及时性</div>
                    </td>
                    <td class="el-table__cell is-leaf">
                      <div class="cell">
                        <el-input style="width:80px;"
                                  v-model="form.timelyCore"></el-input>
                      </div>
                    </td>
                  </tr>
                  <tr style="height:80px;">
                    <td class="el-table__cell is-leaf">
                      <div class="cell">解答态度</div>
                    </td>
                    <td class="el-table__cell is-leaf">
                      <div class="cell">
                        <el-input style="width:80px;"
                                  v-model="form.attitudeCore"></el-input>
                      </div>
                    </td>
                  </tr>
                  <tr style="height:80px;">
                    <td class="el-table__cell is-leaf">
                      <div class="cell">质检评鉴</div>
                    </td>
                    <td class="el-table__cell is-leaf">
                      <div class="cell">
                        <el-input style="width:150px;"
                                  v-model="form.remark"></el-input>
                      </div>
                    </td>
                  </tr>
                </tbody>
              </table>
            </div>
          </el-card>
        </el-col>
      </el-row>
      <el-row type="flex"
              class="row-bg"
              justify="space-around">
        <el-col :span="6">
          <div>
            <el-button type="primary"
                       @click="closeDrawer">确 定</el-button>
          </div>
        </el-col>
        <el-col :span="6">
          <div>总分：{{totalCore}}</div>
        </el-col>
        <el-col :span="6">
          <div>质检人：{{form.qualitiedBy}}</div>
        </el-col>
      </el-row>
    </el-drawer>
    <!-- 分页组件 -->
    <pagination v-show="total>0"
                :total="total"
                :page.sync="queryParams.pageNum"
                :limit.sync="queryParams.pageSize"
                @pagination="getList" />

  </div>
</template>

<script>
// import { listJob, getJob, delJob, addJob, updateJob, runJob, changeJobStatus } from "@/api/monitor/job";
// import Crontab from '@/components/Crontab'
import { selectRepairList } from '@/api/work/myorder'
// import { selectQualitiedByRepairId } from '@/api/work/qualitied'
export default {
  dicts: ['rp_repair_order_status', 'sys_normal_disable'],
  // components: { Crontab },
  name: 'orderList',
  data() {
    return {
      //我的变量
      drawer: false,
      //总分
      totalCore: 0,
      //时间选择器
      value1: new Date(2016, 9, 10, 18, 40),
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 定时任务表格数据
      myOrderList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 是否显示详细弹出层
      openView: false,

      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        repairNo: undefined,
        repairStatus: undefined,
      },
      //工单状态
      options: [
        {
          value: '1',
          label: '工单受理中',
        },
        {
          value: '2',
          label: '工单已派单',
        },
        {
          value: '3',
          label: '待您反馈',
        },
        {
          value: '4',
          label: '正在为您处理',
        },
        {
          value: '5',
          label: '工单已关闭',
        },
      ],
      //工单质检状态
      value: '',
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        repairNo: [
          { required: true, message: '工单编号不能为空', trigger: 'blur' },
        ],
        repairStatus: [
          { required: true, message: '工单状态不能为空', trigger: 'blur' },
        ],
        create_time: [
          { required: true, message: '提交时间不能为空', trigger: 'blur' },
        ],
      },
    }
  },
  created() {
    this.getList()
  },
  methods: {
    closeDrawer() {
      this.drawer = false
    },
    //字典解释器
    formatempempPolitics(row) {
      return this.selectDictLabel(
        this.dict.type.rp_repairStatus,
        row.qualitiedStatus
      )
      l
    },
    /** 查询我的质检页面工单列表 */
    getList() {
      this.loading = true
      selectRepairList(this.queryParams).then((res) => {
        console.log(res)
        this.$modal.msgSuccess(res.msg)
        this.myOrderList = res.rows
        this.total = res.total
        //加载的动画效果
        this.loading = false
      })
    },

    // 表单重置
    reset() {
      this.form = {
        repairNo: undefined,

        ro_status: undefined,
        create_time: undefined,
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      console.log(this.queryParams)
      this.queryParams.pageNum = 1
      this.getList(this.queryParams)
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.order_qualitied)
      this.single = selection.length != 1
      this.multiple = !selection.length
    },

    /** 修改按钮操作 */
    handleUpdate(row) {
      console.log(row)
      this.reset()
    },

    /** 查看质检情况操作 */
    handleCheck(row) {
      // const repairNoIds = row.orderNo || this.ids
      // this.$modal
      //   .confirm('是否确认删除定时任务编号为"' + repairNoIds + '"的数据项？')
      //   .then(function () {
      //     return delOrder(repairNoIds)
      //   })
      //   .then(() => {
      //     this.getList()
      //     this.$modal.msgSuccess('删除成功')
      //   })
      //   .catch(() => {})
      // console.log(row)
      this.drawer = true
      selectQualitiedByRepairId(row.repairOrderId).then((res) => {
        console.log(res)
        this.form = res.data
        this.totalCore =
          parseInt(res.data.languageCore) +
          parseInt(res.data.timelyCore) +
          parseInt(res.data.attitudeCore)
      })
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        'monitor/job/export',
        {
          ...this.queryParams,
        },
        `order_${new Date().getTime()}.xlsx`
      )
    },
  },
}
</script>

